from django.db import models


# Create your models here.
class goods(models.Model):
    name = models.CharField(max_length=20)
    number = models.FloatField()
    price = models.DecimalField(max_digits=10, decimal_places=3, default=0)
    barcode = models.CharField(max_length=20, unique=True, blank=True, null=True)


class Sales(models.Model):
    id = models.AutoField(primary_key=True)
    idGoods = models.SmallIntegerField()
    num = models.IntegerField()
    price = models.DecimalField(max_digits=10, decimal_places=3)
    explain = models.CharField(max_length=20)
    image = models.ImageField()
    flag = models.BooleanField()
    saleDT = models.DateTimeField()


class ExtensionInf(models.Model):
    spec = models.CharField(max_length=40)
    color = models.CharField(max_length=10)
    origin = models.CharField(max_length=60)
    photo = models.ImageField()
    goods = models.OneToOneField(to_field='id', to='goods', on_delete=models.CASCADE, blank=True, null=1)


class Sale_M(models.Model):
    shopname = models.CharField(max_length=30)
    call = models.CharField(max_length=15, blank=True, null=True)
    cashier = models.CharField(max_length=12)
    saletime = models.DateTimeField()


class Sale_Detail(models.Model):
    name = models.CharField(max_length=20)
    number = models.FloatField()
    price = models.DecimalField(max_digits=10, decimal_places=3, default=0)
    Mlink = models.ForeignKey('Sale_M', on_delete=models.CASCADE)


class Book(models.Model):
    bname = models.CharField(max_length=20)
    press = models.CharField(max_length=30)
    cost = models.DecimalField(max_digits=10, decimal_places=3)


class Author(models.Model):
    name = models.CharField(max_length=30)
    call = models.CharField(max_length=13, blank=True, null=True)
    address = models.CharField(max_length=50)
    GetTime = models.DateTimeField()
    MToM = models.ManyToManyField(Book, blank=True)


